package org.netEase.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.netEase.dao.addressDao;
import org.netEase.dao.impl.addressDaoimpl;
import org.netEase.entity.address;
@WebServlet(urlPatterns= {"/updSCAddress.shtml"})
public class updSCAddress extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		addressDao addressDao = new addressDaoimpl();
		String dzId = request.getParameter("dzid");
		address address=addressDao.getlistbydzid(Integer.parseInt(dzId));
		request.setAttribute("address", address);
		request.getRequestDispatcher("/gopayment.jsp").forward(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String dzid = request.getParameter("dzid");
		String Hid = request.getParameter("Hid");
		String shName = request.getParameter("peoples");
		String address1 = request.getParameter("provinces");
		String address2 = request.getParameter("citys");
		String address3=  request.getParameter("areas");
		String xiangxi = request.getParameter("detailsaddresss");
		String phone = request.getParameter("phones");
		
		address address = new address();
		address.setAddress1(address1);
		address.setAddress2(address2);
		address.setAddress3(address3);
		address.setDzid(Integer.parseInt(dzid));
		address.setHid(Integer.parseInt(Hid));
		address.setPhone(phone);
		address.setShname(shName);
		address.setXiangxi(xiangxi);
		
		addressDao addressDao = new addressDaoimpl();
		
		int rows = addressDao.updadd(address);
		if (rows >0) {
			request.setAttribute("kai", "kai");
			request.setAttribute("address", address);
			request.getRequestDispatcher("/gopayment.jsp").forward(request, response);
		}
	}
}
